from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
from launch_ros.actions import Node


def generate_launch_description():

    scanner = LaunchConfiguration('scanner')

    return LaunchDescription([

        # namespace 参数（可选）
        DeclareLaunchArgument(
            name='scanner',
            default_value='dog',
            description='Namespace for LiDAR topics'
        ),

        # ================================
        # 点云 → LaserScan
        # ================================
        Node(
            package='pointcloud_to_laserscan',
            executable='pointcloud_to_laserscan_node',
            name='pointcloud_to_laserscan',

            # 输入和输出 remap
            remappings=[
                ('cloud_in', '/rslidar_points_synced'),
                ('scan', '/scan')
            ],

            # 参数
            parameters=[{
                'target_frame': 'rslidar',

                'transform_tolerance': 0.01,
                'min_height': -0.3,
                'max_height': 0.3,

                'angle_min': -3.14,
                'angle_max':  3.14,
                'angle_increment': 0.004,

                'range_min': 0.3,
                'range_max': 20.0,

                'use_inf': True,
                'inf_epsilon': 1.0,
            }]
        )
    ])
